package com.xidian.GMS.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xidian.GMS.entity.State;
import com.xidian.GMS.entity.Users;
import com.xidian.GMS.service.RegisterService;

@Controller
public class RegisterController {

	@Autowired
	private RegisterService registerService;
	
	@RequestMapping(value="/register",method=RequestMethod.GET)
	public String show(){
		return "forward:/WEB-INF/views/register.html";
	}
	
	@RequestMapping(value="/register",method=RequestMethod.POST)
	@ResponseBody
	public State register(Users user){
		State state = new State();
		System.out.println(user);
		boolean flag = registerService.Register(user);
		if(flag == false){
			state.setSuccess("0");
			return state;
		}else {
			state.setSuccess("1");
			return state;
		}
	}
	@RequestMapping(value="/repassword",method=RequestMethod.GET)
	public String show(Users user){
		
			return "repassword";
	}
	
	@RequestMapping(value="/repassword",method=RequestMethod.POST)
	public String repassword(Users user){
		System.out.println(user);
		boolean flag = registerService.repassword(user);
		if(flag == false){
			return "repassword";
		}else {
			return "repasswordIndex";
		}
	}
} 
